﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HalconDotNet;
namespace _2DLineCamera
{
   public static class Algorithm
    {
        public static void Add_Measure_Point(HObject ho_Image, HObject ho_ROI_0, out HObject ho_Circle, out HTuple hv_Row, out HTuple hv_Column)
        {



            // Local iconic variables 

            HObject ho_ImageReduced, ho_Region, ho_Rectangle;

            // Local control variables 

            HTuple hv_Row1 = new HTuple(), hv_Column1 = new HTuple();
            HTuple hv_Row2 = new HTuple(), hv_Column2 = new HTuple();
            HTuple hv_Area = new HTuple();
            // Initialize local and output iconic variables 
            HOperatorSet.GenEmptyObj(out ho_Circle);
            HOperatorSet.GenEmptyObj(out ho_ImageReduced);
            HOperatorSet.GenEmptyObj(out ho_Region);
            HOperatorSet.GenEmptyObj(out ho_Rectangle);
            hv_Row = new HTuple();
            hv_Column = new HTuple();
            ho_ImageReduced.Dispose();
            HOperatorSet.ReduceDomain(ho_Image, ho_ROI_0, out ho_ImageReduced);
            ho_Region.Dispose();
            HOperatorSet.Threshold(ho_ImageReduced, out ho_Region, 60, 255);
            hv_Row1.Dispose(); hv_Column1.Dispose(); hv_Row2.Dispose(); hv_Column2.Dispose();
            HOperatorSet.SmallestRectangle1(ho_Region, out hv_Row1, out hv_Column1, out hv_Row2,
                out hv_Column2);
            ho_Rectangle.Dispose();
            HOperatorSet.GenRectangle1(out ho_Rectangle, hv_Row1, hv_Column1, hv_Row2, hv_Column2);
            hv_Area.Dispose(); hv_Row.Dispose(); hv_Column.Dispose();
            HOperatorSet.AreaCenter(ho_Rectangle, out hv_Area, out hv_Row, out hv_Column);
            ho_Circle.Dispose();
            HOperatorSet.GenCircle(out ho_Circle, hv_Row, hv_Column, 10);
            ho_ImageReduced.Dispose();
            ho_Region.Dispose();
            ho_Rectangle.Dispose();

            hv_Row1.Dispose();
            hv_Column1.Dispose();
            hv_Row2.Dispose();
            hv_Column2.Dispose();
            hv_Area.Dispose();

            return;
        }

        public static void GetlineL(HTuple hv_Row1, HTuple hv_Col1, HTuple hv_Row2, HTuple hv_Col2,out HTuple hv_Deg, out HTuple hv_RowStart, out HTuple hv_ColStart, out HTuple hv_RowEnd,out HTuple hv_ColEnd)
        {



            // Local iconic variables 

            HObject ho_Line2;

            // Local control variables 

            HTuple hv_RowCenter = new HTuple(), hv_ColCenter = new HTuple();
            HTuple hv_Length = new HTuple(), hv_Phi = new HTuple();
            HTuple hv_LineLength = new HTuple();
            // Initialize local and output iconic variables 
            HOperatorSet.GenEmptyObj(out ho_Line2);
            hv_Deg = new HTuple();
            hv_RowStart = new HTuple();
            hv_ColStart = new HTuple();
            hv_RowEnd = new HTuple();
            hv_ColEnd = new HTuple();
            //获取该直线的位置信息
            hv_RowCenter.Dispose(); hv_ColCenter.Dispose(); hv_Length.Dispose(); hv_Phi.Dispose();
            HOperatorSet.LinePosition(hv_Row1, hv_Col1, hv_Row2, hv_Col2, out hv_RowCenter,
                out hv_ColCenter, out hv_Length, out hv_Phi);
            hv_Deg.Dispose();
            HOperatorSet.TupleDeg(hv_Phi, out hv_Deg);
            //********************生成延长线***********************
            //延长线长度（不精确）
            hv_LineLength.Dispose();
            hv_LineLength = 15000;
            //起点
            hv_RowStart.Dispose();
            using (HDevDisposeHelper dh = new HDevDisposeHelper())
            {
                hv_RowStart = hv_RowCenter - ((((hv_Phi + 1.5708)).TupleCos()
                    ) * hv_LineLength);
            }
            hv_ColStart.Dispose();
            using (HDevDisposeHelper dh = new HDevDisposeHelper())
            {
                hv_ColStart = hv_ColCenter - ((((hv_Phi + 1.5708)).TupleSin()
                    ) * hv_LineLength);
            }
            //终点
            hv_RowEnd.Dispose();
            using (HDevDisposeHelper dh = new HDevDisposeHelper())
            {
                hv_RowEnd = hv_RowCenter - ((((hv_Phi - 1.5708)).TupleCos()
                    ) * hv_LineLength);
            }
            hv_ColEnd.Dispose();
            using (HDevDisposeHelper dh = new HDevDisposeHelper())
            {
                hv_ColEnd = hv_ColCenter - ((((hv_Phi - 1.5708)).TupleSin()
                    ) * hv_LineLength);
            }
            ho_Line2.Dispose();
            HOperatorSet.GenRegionLine(out ho_Line2, hv_RowStart, hv_ColStart, hv_RowEnd,
                hv_ColEnd);
            ho_Line2.Dispose();

            hv_RowCenter.Dispose();
            hv_ColCenter.Dispose();
            hv_Length.Dispose();
            hv_Phi.Dispose();
            hv_LineLength.Dispose();

            return;
        }

        //public static void Get_Ellipes(HObject ho_Image, HObject ho_ROI_0, out HObject ho_Rectangle,out HTuple hv_centerRow, out HTuple hv_centerCol, out HTuple hv_Row1, out HTuple hv_Column1,out HTuple hv_Row2, out HTuple hv_Column2)
        //{



        //    // Local iconic variables 

        //    HObject ho_ImageReduced, ho_Region, ho_ConnectedRegions;
        //    HObject ho_SelectedRegions, ho_ObjectSelected = null;

        //    // Local control variables 

        //    HTuple hv_Number = new HTuple(), hv_Circularity = new HTuple();
        //    HTuple hv_Max = new HTuple(), hv_Index = new HTuple();
        //    HTuple hv_Area = new HTuple();
        //    // Initialize local and output iconic variables 
        //    HOperatorSet.GenEmptyObj(out ho_Rectangle);
        //    HOperatorSet.GenEmptyObj(out ho_ImageReduced);
        //    HOperatorSet.GenEmptyObj(out ho_Region);
        //    HOperatorSet.GenEmptyObj(out ho_ConnectedRegions);
        //    HOperatorSet.GenEmptyObj(out ho_SelectedRegions);
        //    HOperatorSet.GenEmptyObj(out ho_ObjectSelected);
        //    hv_centerRow = new HTuple();
        //    hv_centerCol = new HTuple();
        //    hv_Row1 = new HTuple();
        //    hv_Column1 = new HTuple();
        //    hv_Row2 = new HTuple();
        //    hv_Column2 = new HTuple();
        //    ho_ImageReduced.Dispose();
        //    HOperatorSet.ReduceDomain(ho_Image, ho_ROI_0, out ho_ImageReduced);
        //    ho_Region.Dispose();
        //    HOperatorSet.Threshold(ho_ImageReduced, out ho_Region, 80, 255);
        //    ho_ConnectedRegions.Dispose();
        //    HOperatorSet.Connection(ho_Region, out ho_ConnectedRegions);
        //    ho_SelectedRegions.Dispose();
        //    HOperatorSet.SelectShape(ho_ConnectedRegions, out ho_SelectedRegions, "area",
        //        "and", 300, 99999);
        //    hv_Number.Dispose();
        //    HOperatorSet.CountObj(ho_SelectedRegions, out hv_Number);
        //    hv_centerRow.Dispose();
        //    hv_centerRow = 0;
        //    hv_centerCol.Dispose();
        //    hv_centerCol = 0;
        //    hv_Row1.Dispose();
        //    hv_Row1 = 0;
        //    hv_Column1.Dispose();
        //    hv_Column1 = 0;
        //    hv_Row2.Dispose();
        //    hv_Row2 = 0;
        //    hv_Column2.Dispose();
        //    hv_Column2 = 0;
        //    if ((int)(new HTuple(hv_Number.TupleGreater(0))) != 0)
        //    {
        //        hv_Circularity.Dispose();
        //        HOperatorSet.Circularity(ho_SelectedRegions, out hv_Circularity);
        //        hv_Max.Dispose();
        //        HOperatorSet.TupleMax(hv_Circularity, out hv_Max);
        //        if ((int)(new HTuple(hv_Max.TupleGreater(0.7))) != 0)
        //        {
        //            hv_Index.Dispose();
        //            HOperatorSet.TupleFindFirst(hv_Circularity, hv_Max, out hv_Index);
        //            using (HDevDisposeHelper dh = new HDevDisposeHelper())
        //            {
        //                ho_ObjectSelected.Dispose();
        //                HOperatorSet.SelectObj(ho_SelectedRegions, out ho_ObjectSelected, hv_Index + 1);
        //            }
        //            hv_Row1.Dispose(); hv_Column1.Dispose(); hv_Row2.Dispose(); hv_Column2.Dispose();
        //            HOperatorSet.SmallestRectangle1(ho_ObjectSelected, out hv_Row1, out hv_Column1,
        //                out hv_Row2, out hv_Column2);
        //            ho_Rectangle.Dispose();
        //            HOperatorSet.GenRectangle1(out ho_Rectangle, hv_Row1, hv_Column1, hv_Row2,
        //                hv_Column2);
        //            hv_Area.Dispose(); hv_centerRow.Dispose(); hv_centerCol.Dispose();
        //            HOperatorSet.AreaCenter(ho_Rectangle, out hv_Area, out hv_centerRow, out hv_centerCol);

        //        }
        //    }
        //    ho_ImageReduced.Dispose();
        //    ho_Region.Dispose();
        //    ho_ConnectedRegions.Dispose();
        //    ho_SelectedRegions.Dispose();
        //    ho_ObjectSelected.Dispose();

        //    hv_Number.Dispose();
        //    hv_Circularity.Dispose();
        //    hv_Max.Dispose();
        //    hv_Index.Dispose();
        //    hv_Area.Dispose();

        //    return;
        //}
        public static void Get_Ellipes(HObject ho_Image, HObject ho_ROI_0, out HObject ho_Rectangle,
    out HTuple hv_centerRow, out HTuple hv_centerCol, out HTuple hv_Row1, out HTuple hv_Column1,
    out HTuple hv_Row2, out HTuple hv_Column2)
        {



            // Local iconic variables 

            HObject ho_ImageReduced, ho_Region, ho_ConnectedRegions;
            HObject ho_SelectedRegions, ho_ObjectSelected = null, ho_Circle = null;

            // Local control variables 

            HTuple hv_Number = new HTuple(), hv_Circularity = new HTuple();
            HTuple hv_Max = new HTuple(), hv_Index = new HTuple();
            HTuple hv_Area = new HTuple();
            // Initialize local and output iconic variables 
            HOperatorSet.GenEmptyObj(out ho_Rectangle);
            HOperatorSet.GenEmptyObj(out ho_ImageReduced);
            HOperatorSet.GenEmptyObj(out ho_Region);
            HOperatorSet.GenEmptyObj(out ho_ConnectedRegions);
            HOperatorSet.GenEmptyObj(out ho_SelectedRegions);
            HOperatorSet.GenEmptyObj(out ho_ObjectSelected);
            HOperatorSet.GenEmptyObj(out ho_Circle);
            hv_centerRow = new HTuple();
            hv_centerCol = new HTuple();
            hv_Row1 = new HTuple();
            hv_Column1 = new HTuple();
            hv_Row2 = new HTuple();
            hv_Column2 = new HTuple();
            ho_ImageReduced.Dispose();
            HOperatorSet.ReduceDomain(ho_Image, ho_ROI_0, out ho_ImageReduced);
            ho_Region.Dispose();
            HOperatorSet.Threshold(ho_ImageReduced, out ho_Region, 80, 255);
            ho_ConnectedRegions.Dispose();
            HOperatorSet.Connection(ho_Region, out ho_ConnectedRegions);
            ho_SelectedRegions.Dispose();
            HOperatorSet.SelectShape(ho_ConnectedRegions, out ho_SelectedRegions, "area",
                "and", 300, 99999);
            hv_Number.Dispose();
            HOperatorSet.CountObj(ho_SelectedRegions, out hv_Number);
            hv_centerRow.Dispose();
            hv_centerRow = 0;
            hv_centerCol.Dispose();
            hv_centerCol = 0;
            hv_Row1.Dispose();
            hv_Row1 = 0;
            hv_Column1.Dispose();
            hv_Column1 = 0;
            hv_Row2.Dispose();
            hv_Row2 = 0;
            hv_Column2.Dispose();
            hv_Column2 = 0;
            if ((int)(new HTuple(hv_Number.TupleGreater(0))) != 0)
            {
                hv_Circularity.Dispose();
                HOperatorSet.Circularity(ho_SelectedRegions, out hv_Circularity);
                hv_Max.Dispose();
                HOperatorSet.TupleMax(hv_Circularity, out hv_Max);
                if ((int)(new HTuple(hv_Max.TupleGreater(0.7))) != 0)
                {
                    hv_Index.Dispose();
                    HOperatorSet.TupleFindFirst(hv_Circularity, hv_Max, out hv_Index);
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        ho_ObjectSelected.Dispose();
                        HOperatorSet.SelectObj(ho_SelectedRegions, out ho_ObjectSelected, hv_Index + 1);
                    }
                    hv_Row1.Dispose(); hv_Column1.Dispose(); hv_Row2.Dispose(); hv_Column2.Dispose();
                    HOperatorSet.SmallestRectangle1(ho_ObjectSelected, out hv_Row1, out hv_Column1,
                        out hv_Row2, out hv_Column2);
                    ho_Rectangle.Dispose();
                    HOperatorSet.GenRectangle1(out ho_Rectangle, hv_Row1, hv_Column1, hv_Row2,
                        hv_Column2);
                    hv_Area.Dispose(); hv_centerRow.Dispose(); hv_centerCol.Dispose();
                    HOperatorSet.AreaCenter(ho_Rectangle, out hv_Area, out hv_centerRow, out hv_centerCol);
                }
                else
                {
                    hv_Row1.Dispose(); hv_Column1.Dispose(); hv_Row2.Dispose(); hv_Column2.Dispose();
                    HOperatorSet.SmallestRectangle1(ho_SelectedRegions, out hv_Row1, out hv_Column1,
                        out hv_Row2, out hv_Column2);
                    ho_Rectangle.Dispose();
                    HOperatorSet.GenRectangle1(out ho_Rectangle, hv_Row1, hv_Column1, hv_Row2,
                        hv_Column2);
                    hv_Area.Dispose(); hv_centerRow.Dispose(); hv_centerCol.Dispose();
                    HOperatorSet.AreaCenter(ho_Rectangle, out hv_Area, out hv_centerRow, out hv_centerCol);
                    ho_Circle.Dispose();
                    HOperatorSet.GenCircle(out ho_Circle, hv_centerRow, hv_centerCol, 10);

                }

            }
            ho_ImageReduced.Dispose();
            ho_Region.Dispose();
            ho_ConnectedRegions.Dispose();
            ho_SelectedRegions.Dispose();
            ho_ObjectSelected.Dispose();
            ho_Circle.Dispose();

            hv_Number.Dispose();
            hv_Circularity.Dispose();
            hv_Max.Dispose();
            hv_Index.Dispose();
            hv_Area.Dispose();

            return;
        }
        public static void Create_Stanrd_model(HObject ho_Image, HObject ho_ROI_0, HTuple hv_path, out HTuple hv_Row, out HTuple hv_Column)
        {

            // Local iconic variables 

            HObject ho_ImageReduced;

            // Local control variables 

            HTuple hv_Area = new HTuple(), hv_ModelID1 = new HTuple();
            // Initialize local and output iconic variables 
            HOperatorSet.GenEmptyObj(out ho_ImageReduced);
            hv_Row = new HTuple();
            hv_Column = new HTuple();
            ho_ImageReduced.Dispose();
            HOperatorSet.ReduceDomain(ho_Image, ho_ROI_0, out ho_ImageReduced);
            hv_Area.Dispose(); hv_Row.Dispose(); hv_Column.Dispose();
            HOperatorSet.AreaCenter(ho_ROI_0, out hv_Area, out hv_Row, out hv_Column);
            using (HDevDisposeHelper dh = new HDevDisposeHelper())
            {
                hv_ModelID1.Dispose();
                HOperatorSet.CreateScaledShapeModel(ho_ImageReduced, "auto", (new HTuple(-30)).TupleRad()
                    , (new HTuple(30)).TupleRad(), "auto", 0.9, 1.1, "auto", "auto", "use_polarity",
                    "auto", "auto", out hv_ModelID1);
            }
            HOperatorSet.WriteShapeModel(hv_ModelID1, hv_path);
            ho_ImageReduced.Dispose();

            hv_Area.Dispose();
            hv_ModelID1.Dispose();

            return;
        }

        public static void Read_Data_Code(HObject ho_Image, HObject ho_ROI_0,out HObject ho_SymbolXLDs, out HTuple hv_DecodedDataStrings)
        {



            // Local iconic variables 

            HObject ho_ImageReduced, ho_ImageScaled, ho_GammaImage, ho_ImageMean;

            // Local control variables 

            HTuple hv_DataCodeHandle = new HTuple(), hv_ResultHandles = new HTuple();
            // Initialize local and output iconic variables 
            HOperatorSet.GenEmptyObj(out ho_SymbolXLDs);
            HOperatorSet.GenEmptyObj(out ho_ImageReduced);
            HOperatorSet.GenEmptyObj(out ho_ImageScaled);
            HOperatorSet.GenEmptyObj(out ho_GammaImage);
            HOperatorSet.GenEmptyObj(out ho_ImageMean);
            hv_DecodedDataStrings = new HTuple();
            ho_ImageReduced.Dispose();
            HOperatorSet.ReduceDomain(ho_Image, ho_ROI_0, out ho_ImageReduced);
            ho_GammaImage.Dispose();
            HOperatorSet.GammaImage(ho_ImageReduced, out ho_GammaImage, 0.416667, 0.055,0.0031308, 255, "true");
            ho_ImageScaled.Dispose();
            HOperatorSet.ScaleImage(ho_GammaImage, out ho_ImageScaled, 30, 80);
            ho_ImageMean.Dispose();
            HOperatorSet.MeanImage(ho_ImageScaled, out ho_ImageMean, 5, 5);
            hv_DataCodeHandle.Dispose();
            HOperatorSet.CreateDataCode2dModel("QR Code", new HTuple(), new HTuple(),
                out hv_DataCodeHandle);
            ho_SymbolXLDs.Dispose(); hv_ResultHandles.Dispose(); hv_DecodedDataStrings.Dispose();
            HOperatorSet.FindDataCode2d(ho_ImageScaled, out ho_SymbolXLDs, hv_DataCodeHandle,
                new HTuple(), new HTuple(), out hv_ResultHandles, out hv_DecodedDataStrings);
            if (hv_DecodedDataStrings.Length==0)
            {
                HOperatorSet.CreateDataCode2dModel("Data Matrix ECC 200", new HTuple(), new HTuple(),
               out hv_DataCodeHandle);
                ho_SymbolXLDs.Dispose(); hv_ResultHandles.Dispose(); hv_DecodedDataStrings.Dispose();
                HOperatorSet.FindDataCode2d(ho_ImageScaled, out ho_SymbolXLDs, hv_DataCodeHandle,
                    new HTuple(), new HTuple(), out hv_ResultHandles, out hv_DecodedDataStrings);
            }
            ho_ImageReduced.Dispose();
            ho_ImageScaled.Dispose();

            hv_DataCodeHandle.Dispose();
            hv_ResultHandles.Dispose();

            return;
        }
        public static void set_display_font(HTuple hv_WindowHandle, HTuple hv_Size, HTuple hv_Font, HTuple hv_Bold, HTuple hv_Slant)
        {



            // Local iconic variables 

            // Local control variables 

            HTuple hv_OS = new HTuple(), hv_Fonts = new HTuple();
            HTuple hv_Style = new HTuple(), hv_Exception = new HTuple();
            HTuple hv_AvailableFonts = new HTuple(), hv_Fdx = new HTuple();
            HTuple hv_Indices = new HTuple();
            HTuple hv_Font_COPY_INP_TMP = new HTuple(hv_Font);
            HTuple hv_Size_COPY_INP_TMP = new HTuple(hv_Size);

            try
            {

                hv_OS.Dispose();
                HOperatorSet.GetSystem("operating_system", out hv_OS);
                if ((int)((new HTuple(hv_Size_COPY_INP_TMP.TupleEqual(new HTuple()))).TupleOr(
                    new HTuple(hv_Size_COPY_INP_TMP.TupleEqual(-1)))) != 0)
                {
                    hv_Size_COPY_INP_TMP.Dispose();
                    hv_Size_COPY_INP_TMP = 16;
                }
                if ((int)(new HTuple(((hv_OS.TupleSubstr(0, 2))).TupleEqual("Win"))) != 0)
                {
                    //Restore previous behaviour
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        {
                            HTuple
                              ExpTmpLocalVar_Size = ((1.13677 * hv_Size_COPY_INP_TMP)).TupleInt()
                                ;
                            hv_Size_COPY_INP_TMP.Dispose();
                            hv_Size_COPY_INP_TMP = ExpTmpLocalVar_Size;
                        }
                    }
                }
                else
                {
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        {
                            HTuple
                              ExpTmpLocalVar_Size = hv_Size_COPY_INP_TMP.TupleInt()
                                ;
                            hv_Size_COPY_INP_TMP.Dispose();
                            hv_Size_COPY_INP_TMP = ExpTmpLocalVar_Size;
                        }
                    }
                }
                if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("Courier"))) != 0)
                {
                    hv_Fonts.Dispose();
                    hv_Fonts = new HTuple();
                    hv_Fonts[0] = "Courier";
                    hv_Fonts[1] = "Courier 10 Pitch";
                    hv_Fonts[2] = "Courier New";
                    hv_Fonts[3] = "CourierNew";
                    hv_Fonts[4] = "Liberation Mono";
                }
                else if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("mono"))) != 0)
                {
                    hv_Fonts.Dispose();
                    hv_Fonts = new HTuple();
                    hv_Fonts[0] = "Consolas";
                    hv_Fonts[1] = "Menlo";
                    hv_Fonts[2] = "Courier";
                    hv_Fonts[3] = "Courier 10 Pitch";
                    hv_Fonts[4] = "FreeMono";
                    hv_Fonts[5] = "Liberation Mono";
                }
                else if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("sans"))) != 0)
                {
                    hv_Fonts.Dispose();
                    hv_Fonts = new HTuple();
                    hv_Fonts[0] = "Luxi Sans";
                    hv_Fonts[1] = "DejaVu Sans";
                    hv_Fonts[2] = "FreeSans";
                    hv_Fonts[3] = "Arial";
                    hv_Fonts[4] = "Liberation Sans";
                }
                else if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("serif"))) != 0)
                {
                    hv_Fonts.Dispose();
                    hv_Fonts = new HTuple();
                    hv_Fonts[0] = "Times New Roman";
                    hv_Fonts[1] = "Luxi Serif";
                    hv_Fonts[2] = "DejaVu Serif";
                    hv_Fonts[3] = "FreeSerif";
                    hv_Fonts[4] = "Utopia";
                    hv_Fonts[5] = "Liberation Serif";
                }
                else
                {
                    hv_Fonts.Dispose();
                    hv_Fonts = new HTuple(hv_Font_COPY_INP_TMP);
                }
                hv_Style.Dispose();
                hv_Style = "";
                if ((int)(new HTuple(hv_Bold.TupleEqual("true"))) != 0)
                {
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        {
                            HTuple
                              ExpTmpLocalVar_Style = hv_Style + "Bold";
                            hv_Style.Dispose();
                            hv_Style = ExpTmpLocalVar_Style;
                        }
                    }
                }
                else if ((int)(new HTuple(hv_Bold.TupleNotEqual("false"))) != 0)
                {
                    hv_Exception.Dispose();
                    hv_Exception = "Wrong value of control parameter Bold";
                    throw new HalconException(hv_Exception);
                }
                if ((int)(new HTuple(hv_Slant.TupleEqual("true"))) != 0)
                {
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        {
                            HTuple
                              ExpTmpLocalVar_Style = hv_Style + "Italic";
                            hv_Style.Dispose();
                            hv_Style = ExpTmpLocalVar_Style;
                        }
                    }
                }
                else if ((int)(new HTuple(hv_Slant.TupleNotEqual("false"))) != 0)
                {
                    hv_Exception.Dispose();
                    hv_Exception = "Wrong value of control parameter Slant";
                    throw new HalconException(hv_Exception);
                }
                if ((int)(new HTuple(hv_Style.TupleEqual(""))) != 0)
                {
                    hv_Style.Dispose();
                    hv_Style = "Normal";
                }
                hv_AvailableFonts.Dispose();
                HOperatorSet.QueryFont(hv_WindowHandle, out hv_AvailableFonts);
                hv_Font_COPY_INP_TMP.Dispose();
                hv_Font_COPY_INP_TMP = "";
                for (hv_Fdx = 0; (int)hv_Fdx <= (int)((new HTuple(hv_Fonts.TupleLength())) - 1); hv_Fdx = (int)hv_Fdx + 1)
                {
                    hv_Indices.Dispose();
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        hv_Indices = hv_AvailableFonts.TupleFind(
                            hv_Fonts.TupleSelect(hv_Fdx));
                    }
                    if ((int)(new HTuple((new HTuple(hv_Indices.TupleLength())).TupleGreater(
                        0))) != 0)
                    {
                        if ((int)(new HTuple(((hv_Indices.TupleSelect(0))).TupleGreaterEqual(0))) != 0)
                        {
                            hv_Font_COPY_INP_TMP.Dispose();
                            using (HDevDisposeHelper dh = new HDevDisposeHelper())
                            {
                                hv_Font_COPY_INP_TMP = hv_Fonts.TupleSelect(
                                    hv_Fdx);
                            }
                            break;
                        }
                    }
                }
                if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual(""))) != 0)
                {
                    throw new HalconException("Wrong value of control parameter Font");
                }
                using (HDevDisposeHelper dh = new HDevDisposeHelper())
                {
                    {
                        HTuple
                          ExpTmpLocalVar_Font = (((hv_Font_COPY_INP_TMP + "-") + hv_Style) + "-") + hv_Size_COPY_INP_TMP;
                        hv_Font_COPY_INP_TMP.Dispose();
                        hv_Font_COPY_INP_TMP = ExpTmpLocalVar_Font;
                    }
                }
                HOperatorSet.SetFont(hv_WindowHandle, hv_Font_COPY_INP_TMP);

                hv_Font_COPY_INP_TMP.Dispose();
                hv_Size_COPY_INP_TMP.Dispose();
                hv_OS.Dispose();
                hv_Fonts.Dispose();
                hv_Style.Dispose();
                hv_Exception.Dispose();
                hv_AvailableFonts.Dispose();
                hv_Fdx.Dispose();
                hv_Indices.Dispose();

                return;
            }
            catch (HalconException HDevExpDefaultException)
            {

                hv_Font_COPY_INP_TMP.Dispose();
                hv_Size_COPY_INP_TMP.Dispose();
                hv_OS.Dispose();
                hv_Fonts.Dispose();
                hv_Style.Dispose();
                hv_Exception.Dispose();
                hv_AvailableFonts.Dispose();
                hv_Fdx.Dispose();
                hv_Indices.Dispose();

                throw HDevExpDefaultException;
            }
        }
        public static void Add_Measure_SemiCircle(HObject ho_Image, HObject ho_ROI_0, out HObject ho_Circle, out HTuple hv_Row, out HTuple hv_Column)
        {



            // Local iconic variables 

            HObject ho_ImageReduced, ho_Region, ho_Rectangle;
            HObject ho_ImageReduced1, ho_Region1;

            // Local control variables 

            HTuple hv_Row1 = new HTuple(), hv_Column1 = new HTuple();
            HTuple hv_Row2 = new HTuple(), hv_Column2 = new HTuple();
            HTuple hv_Row11 = new HTuple(), hv_Column11 = new HTuple();
            HTuple hv_Row21 = new HTuple(), hv_Column21 = new HTuple();
            HTuple hv_Area = new HTuple();
            // Initialize local and output iconic variables 
            HOperatorSet.GenEmptyObj(out ho_Circle);
            HOperatorSet.GenEmptyObj(out ho_ImageReduced);
            HOperatorSet.GenEmptyObj(out ho_Region);
            HOperatorSet.GenEmptyObj(out ho_Rectangle);
            HOperatorSet.GenEmptyObj(out ho_ImageReduced1);
            HOperatorSet.GenEmptyObj(out ho_Region1);
            hv_Row = new HTuple();
            hv_Column = new HTuple();
            ho_ImageReduced.Dispose();
            HOperatorSet.ReduceDomain(ho_Image, ho_ROI_0, out ho_ImageReduced);
            ho_Region.Dispose();
            HOperatorSet.Threshold(ho_ImageReduced, out ho_Region, 0, 75);
            hv_Row1.Dispose(); hv_Column1.Dispose(); hv_Row2.Dispose(); hv_Column2.Dispose();
            HOperatorSet.SmallestRectangle1(ho_Region, out hv_Row1, out hv_Column1, out hv_Row2,
                out hv_Column2);
            using (HDevDisposeHelper dh = new HDevDisposeHelper())
            {
                ho_Rectangle.Dispose();
                HOperatorSet.GenRectangle1(out ho_Rectangle, hv_Row1, hv_Column1 - 10, hv_Row2,
                    hv_Column2 - 10);
            }
            ho_ImageReduced1.Dispose();
            HOperatorSet.ReduceDomain(ho_ImageReduced, ho_Rectangle, out ho_ImageReduced1
                );
            ho_Region1.Dispose();
            HOperatorSet.Threshold(ho_ImageReduced1, out ho_Region1, 128, 255);
            hv_Row11.Dispose(); hv_Column11.Dispose(); hv_Row21.Dispose(); hv_Column21.Dispose();
            HOperatorSet.SmallestRectangle1(ho_Region1, out hv_Row11, out hv_Column11, out hv_Row21,
                out hv_Column21);
            hv_Area.Dispose(); hv_Row.Dispose(); hv_Column.Dispose();
            HOperatorSet.AreaCenter(ho_Region1, out hv_Area, out hv_Row, out hv_Column);
            ho_Circle.Dispose();
            HOperatorSet.GenCircle(out ho_Circle, hv_Row, hv_Column, 20);
            ho_ImageReduced.Dispose();
            ho_Region.Dispose();
            ho_Rectangle.Dispose();
            ho_ImageReduced1.Dispose();
            ho_Region1.Dispose();

            hv_Row1.Dispose();
            hv_Column1.Dispose();
            hv_Row2.Dispose();
            hv_Column2.Dispose();
            hv_Row11.Dispose();
            hv_Column11.Dispose();
            hv_Row21.Dispose();
            hv_Column21.Dispose();
            hv_Area.Dispose();

            return;
        }
       
        //public static void Get_Radius(HObject ho_Image, HObject ho_ROI_0, out HObject ho_Circle, out HTuple hv_Radius, out HTuple hv_Row, out HTuple hv_Column)
        //{



        //    // Local iconic variables 

        //    HObject ho_ImageReduced, ho_Region, ho_ConnectedRegions;
        //    HObject ho_SelectedRegions, ho_ObjectSelected = null, ho_Rectangle = null;

        //    // Local control variables 

        //    HTuple hv_Number = new HTuple(), hv_Circularity = new HTuple();
        //    HTuple hv_Max = new HTuple(), hv_Index = new HTuple();
        //    HTuple hv_Row1 = new HTuple(), hv_Column1 = new HTuple();
        //    HTuple hv_Row2 = new HTuple(), hv_Column2 = new HTuple();
        //    HTuple hv_Rectangle_Width = new HTuple(), hv_Rectangle_Hight = new HTuple();
        //    HTuple hv_Area = new HTuple();
        //    // Initialize local and output iconic variables 
        //    HOperatorSet.GenEmptyObj(out ho_Circle);
        //    HOperatorSet.GenEmptyObj(out ho_ImageReduced);
        //    HOperatorSet.GenEmptyObj(out ho_Region);
        //    HOperatorSet.GenEmptyObj(out ho_ConnectedRegions);
        //    HOperatorSet.GenEmptyObj(out ho_SelectedRegions);
        //    HOperatorSet.GenEmptyObj(out ho_ObjectSelected);
        //    HOperatorSet.GenEmptyObj(out ho_Rectangle);
        //    hv_Radius = new HTuple();
        //    hv_Row = new HTuple();
        //    hv_Column = new HTuple();
        //    ho_ImageReduced.Dispose();
        //    HOperatorSet.ReduceDomain(ho_Image, ho_ROI_0, out ho_ImageReduced);
        //    ho_Region.Dispose();
        //    HOperatorSet.Threshold(ho_ImageReduced, out ho_Region, 80, 255);
        //    ho_ConnectedRegions.Dispose();
        //    HOperatorSet.Connection(ho_Region, out ho_ConnectedRegions);
        //    ho_SelectedRegions.Dispose();
        //    HOperatorSet.SelectShape(ho_ConnectedRegions, out ho_SelectedRegions, "area",
        //        "and", 300, 99999);
        //    hv_Number.Dispose();
        //    HOperatorSet.CountObj(ho_SelectedRegions, out hv_Number);
        //    hv_Radius.Dispose();
        //    hv_Radius = 0;
        //    hv_Row.Dispose();
        //    hv_Row = 0;
        //    hv_Column.Dispose();
        //    hv_Column = 0;
        //    if ((int)(new HTuple(hv_Number.TupleGreater(0))) != 0)
        //    {
        //        hv_Circularity.Dispose();
        //        HOperatorSet.Circularity(ho_SelectedRegions, out hv_Circularity);
        //        hv_Max.Dispose();
        //        HOperatorSet.TupleMax(hv_Circularity, out hv_Max);
        //        if ((int)(new HTuple(hv_Max.TupleGreater(0.7))) != 0)
        //        {
        //            hv_Index.Dispose();
        //            HOperatorSet.TupleFindFirst(hv_Circularity, hv_Max, out hv_Index);
        //            using (HDevDisposeHelper dh = new HDevDisposeHelper())
        //            {
        //                ho_ObjectSelected.Dispose();
        //                HOperatorSet.SelectObj(ho_SelectedRegions, out ho_ObjectSelected, hv_Index + 1);
        //            }
        //            hv_Row1.Dispose(); hv_Column1.Dispose(); hv_Row2.Dispose(); hv_Column2.Dispose();
        //            HOperatorSet.SmallestRectangle1(ho_ObjectSelected, out hv_Row1, out hv_Column1,
        //                out hv_Row2, out hv_Column2);
        //            ho_Rectangle.Dispose();
        //            HOperatorSet.GenRectangle1(out ho_Rectangle, hv_Row1, hv_Column1, hv_Row2,
        //                hv_Column2);
        //            hv_Rectangle_Width.Dispose();
        //            using (HDevDisposeHelper dh = new HDevDisposeHelper())
        //            {
        //                hv_Rectangle_Width = hv_Column2 - hv_Column1;
        //            }
        //            hv_Rectangle_Hight.Dispose();
        //            using (HDevDisposeHelper dh = new HDevDisposeHelper())
        //            {
        //                hv_Rectangle_Hight = hv_Row2 - hv_Row1;
        //            }

        //            if ((int)(new HTuple(hv_Rectangle_Width.TupleGreater(hv_Rectangle_Hight))) != 0)
        //            {
        //                hv_Radius.Dispose();
        //                hv_Radius = new HTuple(hv_Rectangle_Hight);
        //            }
        //            else
        //            {
        //                hv_Radius.Dispose();
        //                hv_Radius = new HTuple(hv_Rectangle_Width);
        //            }
        //            hv_Area.Dispose(); hv_Row.Dispose(); hv_Column.Dispose();
        //            HOperatorSet.AreaCenter(ho_Rectangle, out hv_Area, out hv_Row, out hv_Column);
        //            ho_Circle.Dispose();
        //            HOperatorSet.GenCircle(out ho_Circle, hv_Row, hv_Column, 10);
        //        }

        //    }
        //    ho_ImageReduced.Dispose();
        //    ho_Region.Dispose();
        //    ho_ConnectedRegions.Dispose();
        //    ho_SelectedRegions.Dispose();
        //    ho_ObjectSelected.Dispose();
        //    ho_Rectangle.Dispose();

        //    hv_Number.Dispose();
        //    hv_Circularity.Dispose();
        //    hv_Max.Dispose();
        //    hv_Index.Dispose();
        //    hv_Row1.Dispose();
        //    hv_Column1.Dispose();
        //    hv_Row2.Dispose();
        //    hv_Column2.Dispose();
        //    hv_Rectangle_Width.Dispose();
        //    hv_Rectangle_Hight.Dispose();
        //    hv_Area.Dispose();

        //    return;
        //}
       
        
        public static void Get_Radius(HObject ho_Image, HObject ho_ROI_0, out HObject ho_Circle,out HTuple hv_Radius, out HTuple hv_Row, out HTuple hv_Column)
        {



            // Local iconic variables 

            HObject ho_ImageReduced, ho_Region, ho_ConnectedRegions;
            HObject ho_SelectedRegions, ho_ObjectSelected = null, ho_Rectangle = null;

            // Local control variables 

            HTuple hv_Number = new HTuple(), hv_Circularity = new HTuple();
            HTuple hv_Max = new HTuple(), hv_Index = new HTuple();
            HTuple hv_Row1 = new HTuple(), hv_Column1 = new HTuple();
            HTuple hv_Row2 = new HTuple(), hv_Column2 = new HTuple();
            HTuple hv_Rectangle_Width = new HTuple(), hv_Rectangle_Hight = new HTuple();
            HTuple hv_Area = new HTuple();
            // Initialize local and output iconic variables 
            HOperatorSet.GenEmptyObj(out ho_Circle);
            HOperatorSet.GenEmptyObj(out ho_ImageReduced);
            HOperatorSet.GenEmptyObj(out ho_Region);
            HOperatorSet.GenEmptyObj(out ho_ConnectedRegions);
            HOperatorSet.GenEmptyObj(out ho_SelectedRegions);
            HOperatorSet.GenEmptyObj(out ho_ObjectSelected);
            HOperatorSet.GenEmptyObj(out ho_Rectangle);
            hv_Radius = new HTuple();
            hv_Row = new HTuple();
            hv_Column = new HTuple();
            ho_ImageReduced.Dispose();
            HOperatorSet.ReduceDomain(ho_Image, ho_ROI_0, out ho_ImageReduced);
            ho_Region.Dispose();
            HOperatorSet.Threshold(ho_ImageReduced, out ho_Region, 80, 255);
            ho_ConnectedRegions.Dispose();
            HOperatorSet.Connection(ho_Region, out ho_ConnectedRegions);
            ho_SelectedRegions.Dispose();
            HOperatorSet.SelectShape(ho_ConnectedRegions, out ho_SelectedRegions, "area",
                "and", 300, 99999);
            hv_Number.Dispose();
            HOperatorSet.CountObj(ho_SelectedRegions, out hv_Number);
            hv_Radius.Dispose();
            hv_Radius = 0;
            hv_Row.Dispose();
            hv_Row = 0;
            hv_Column.Dispose();
            hv_Column = 0;
            if ((int)(new HTuple(hv_Number.TupleGreater(0))) != 0)
            {
                hv_Circularity.Dispose();
                HOperatorSet.Circularity(ho_SelectedRegions, out hv_Circularity);
                hv_Max.Dispose();
                HOperatorSet.TupleMax(hv_Circularity, out hv_Max);
                if ((int)(new HTuple(hv_Max.TupleGreater(0.7))) != 0)
                {
                    hv_Index.Dispose();
                    HOperatorSet.TupleFindFirst(hv_Circularity, hv_Max, out hv_Index);
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        ho_ObjectSelected.Dispose();
                        HOperatorSet.SelectObj(ho_SelectedRegions, out ho_ObjectSelected, hv_Index + 1);
                    }
                    hv_Row1.Dispose(); hv_Column1.Dispose(); hv_Row2.Dispose(); hv_Column2.Dispose();
                    HOperatorSet.SmallestRectangle1(ho_ObjectSelected, out hv_Row1, out hv_Column1,
                        out hv_Row2, out hv_Column2);
                    ho_Rectangle.Dispose();
                    HOperatorSet.GenRectangle1(out ho_Rectangle, hv_Row1, hv_Column1, hv_Row2,
                        hv_Column2);
                    hv_Rectangle_Width.Dispose();
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        hv_Rectangle_Width = hv_Column2 - hv_Column1;
                    }
                    hv_Rectangle_Hight.Dispose();
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        hv_Rectangle_Hight = hv_Row2 - hv_Row1;
                    }

                    if ((int)(new HTuple(hv_Rectangle_Width.TupleGreater(hv_Rectangle_Hight))) != 0)
                    {
                        hv_Radius.Dispose();
                        hv_Radius = new HTuple(hv_Rectangle_Hight);
                    }
                    else
                    {
                        hv_Radius.Dispose();
                        hv_Radius = new HTuple(hv_Rectangle_Width);
                    }
                    hv_Area.Dispose(); hv_Row.Dispose(); hv_Column.Dispose();
                    HOperatorSet.AreaCenter(ho_Rectangle, out hv_Area, out hv_Row, out hv_Column);
                    ho_Circle.Dispose();
                    HOperatorSet.GenCircle(out ho_Circle, hv_Row, hv_Column, 10);
                }
                else
                {
                    hv_Row1.Dispose(); hv_Column1.Dispose(); hv_Row2.Dispose(); hv_Column2.Dispose();
                    HOperatorSet.SmallestRectangle1(ho_SelectedRegions, out hv_Row1, out hv_Column1,
                        out hv_Row2, out hv_Column2);
                    ho_Rectangle.Dispose();
                    HOperatorSet.GenRectangle1(out ho_Rectangle, hv_Row1, hv_Column1, hv_Row2,
                        hv_Column2);
                    hv_Rectangle_Width.Dispose();
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        hv_Rectangle_Width = hv_Column2 - hv_Column1;
                    }
                    hv_Rectangle_Hight.Dispose();
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        hv_Rectangle_Hight = hv_Row2 - hv_Row1;
                    }

                    if ((int)(new HTuple(hv_Rectangle_Width.TupleGreater(hv_Rectangle_Hight))) != 0)
                    {
                        hv_Radius.Dispose();
                        hv_Radius = new HTuple(hv_Rectangle_Hight);
                    }
                    else
                    {
                        hv_Radius.Dispose();
                        hv_Radius = new HTuple(hv_Rectangle_Width);
                    }
                    hv_Area.Dispose(); hv_Row.Dispose(); hv_Column.Dispose();
                    HOperatorSet.AreaCenter(ho_Rectangle, out hv_Area, out hv_Row, out hv_Column);
                    ho_Circle.Dispose();
                    HOperatorSet.GenCircle(out ho_Circle, hv_Row, hv_Column, 10);
                }

            }
            ho_ImageReduced.Dispose();
            ho_Region.Dispose();
            ho_ConnectedRegions.Dispose();
            ho_SelectedRegions.Dispose();
            ho_ObjectSelected.Dispose();
            ho_Rectangle.Dispose();

            hv_Number.Dispose();
            hv_Circularity.Dispose();
            hv_Max.Dispose();
            hv_Index.Dispose();
            hv_Row1.Dispose();
            hv_Column1.Dispose();
            hv_Row2.Dispose();
            hv_Column2.Dispose();
            hv_Rectangle_Width.Dispose();
            hv_Rectangle_Hight.Dispose();
            hv_Area.Dispose();

            return;
        }
        public static void GetPinHW(HObject ho_ImageReduced1, HTuple hv_CameraParam, HTuple hv_Pose,
     HTuple hv_Rowwy, HTuple hv_Columnwy, out HTuple hv_NYX, out HTuple hv_NYY, out HTuple hv_YXRow,
     out HTuple hv_YXColumn)
        {




            // Local iconic variables 

            HObject ho_Region1, ho_RegionOpening, ho_ConnectedRegions1;
            HObject ho_SelectedRegions3, ho_SelectedRegions4 = null, ho_SelectedRegions5;
            HObject ho_Rectangle1 = null;

            // Local control variables 

            HTuple hv_Number1 = new HTuple(), hv_Number2 = new HTuple();
            HTuple hv_Row11 = new HTuple(), hv_Column11 = new HTuple();
            HTuple hv_Row21 = new HTuple(), hv_Column21 = new HTuple();
            HTuple hv_Areany = new HTuple(), hv_Rowny = new HTuple();
            HTuple hv_Columnny = new HTuple(), hv_Nyx = new HTuple();
            HTuple hv_Nyy = new HTuple(), hv_Nyx1 = new HTuple(), hv_Nyy1 = new HTuple();
            HTuple hv_Yxnyx = new HTuple(), hv_Yxnyy = new HTuple();
            HTuple hv_Yxxwyx = new HTuple(), hv_Yxywyy = new HTuple();
            // Initialize local and output iconic variables 
            HOperatorSet.GenEmptyObj(out ho_Region1);
            HOperatorSet.GenEmptyObj(out ho_RegionOpening);
            HOperatorSet.GenEmptyObj(out ho_ConnectedRegions1);
            HOperatorSet.GenEmptyObj(out ho_SelectedRegions3);
            HOperatorSet.GenEmptyObj(out ho_SelectedRegions4);
            HOperatorSet.GenEmptyObj(out ho_SelectedRegions5);
            HOperatorSet.GenEmptyObj(out ho_Rectangle1);
            hv_NYX = new HTuple();
            hv_NYY = new HTuple();
            hv_YXRow = new HTuple();
            hv_YXColumn = new HTuple();
            hv_NYX.Dispose();
            hv_NYX = 0;
            hv_NYY.Dispose();
            hv_NYY = 0;
            hv_YXRow.Dispose();
            hv_YXRow = 0;
            hv_YXColumn.Dispose();
            hv_YXColumn = 0;
            ho_Region1.Dispose();
            HOperatorSet.Threshold(ho_ImageReduced1, out ho_Region1, 0, 200);
            ho_RegionOpening.Dispose();
            HOperatorSet.OpeningCircle(ho_Region1, out ho_RegionOpening, 5);
            ho_ConnectedRegions1.Dispose();
            HOperatorSet.Connection(ho_RegionOpening, out ho_ConnectedRegions1);
            ho_SelectedRegions3.Dispose();
            HOperatorSet.SelectShape(ho_ConnectedRegions1, out ho_SelectedRegions3, "width",
                "and", 30, 80);
            hv_Number1.Dispose();
            HOperatorSet.CountObj(ho_SelectedRegions3, out hv_Number1);
            if ((int)(new HTuple(hv_Number1.TupleNotEqual(0))) != 0)
            {
                ho_SelectedRegions4.Dispose();
                HOperatorSet.SelectShape(ho_SelectedRegions3, out ho_SelectedRegions4, "height",
                    "and", 20, 70);
            }
            ho_SelectedRegions5.Dispose();
            HOperatorSet.SelectShape(ho_SelectedRegions4, out ho_SelectedRegions5, "area",
                "and", 500, 99999);
            hv_Number2.Dispose();
            HOperatorSet.CountObj(ho_SelectedRegions5, out hv_Number2);
            if ((int)(new HTuple(hv_Number2.TupleNotEqual(0))) != 0)
            {
                hv_Row11.Dispose(); hv_Column11.Dispose(); hv_Row21.Dispose(); hv_Column21.Dispose();
                HOperatorSet.SmallestRectangle1(ho_SelectedRegions5, out hv_Row11, out hv_Column11,
                    out hv_Row21, out hv_Column21);
                ho_Rectangle1.Dispose();
                HOperatorSet.GenRectangle1(out ho_Rectangle1, hv_Row11, hv_Column11, hv_Row21,
                    hv_Column21);
                //内圆中心坐标
                hv_Areany.Dispose(); hv_Rowny.Dispose(); hv_Columnny.Dispose();
                HOperatorSet.AreaCenter(ho_SelectedRegions3, out hv_Areany, out hv_Rowny, out hv_Columnny);
                //获取内矩形长宽
                hv_Nyx.Dispose(); hv_Nyy.Dispose();
                HOperatorSet.ImagePointsToWorldPlane(hv_CameraParam, hv_Pose, hv_Row11, hv_Column11,
                    "mm", out hv_Nyx, out hv_Nyy);
                hv_Nyx1.Dispose(); hv_Nyy1.Dispose();
                HOperatorSet.ImagePointsToWorldPlane(hv_CameraParam, hv_Pose, hv_Row21, hv_Column21,
                    "mm", out hv_Nyx1, out hv_Nyy1);
                //长宽
                hv_NYX.Dispose();
                using (HDevDisposeHelper dh = new HDevDisposeHelper())
                {
                    hv_NYX = hv_Nyx1 - hv_Nyx;
                }
                if ((int)(new HTuple(hv_NYX.TupleLess(0))) != 0)
                {
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        {
                            HTuple
                              ExpTmpLocalVar_NYX = -hv_NYX;
                            hv_NYX.Dispose();
                            hv_NYX = ExpTmpLocalVar_NYX;
                        }
                    }
                }
                hv_NYY.Dispose();
                using (HDevDisposeHelper dh = new HDevDisposeHelper())
                {
                    hv_NYY = hv_Nyy1 - hv_Nyy;
                }
                if ((int)(new HTuple(hv_NYY.TupleLess(0))) != 0)
                {
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        {
                            HTuple
                              ExpTmpLocalVar_NYY = -hv_NYY;
                            hv_NYY.Dispose();
                            hv_NYY = ExpTmpLocalVar_NYY;
                        }
                    }
                }
                //圆心比较
                hv_Yxnyx.Dispose(); hv_Yxnyy.Dispose();
                HOperatorSet.ImagePointsToWorldPlane(hv_CameraParam, hv_Pose, hv_Rowny, hv_Columnny,
                    "mm", out hv_Yxnyx, out hv_Yxnyy);
                hv_Yxxwyx.Dispose(); hv_Yxywyy.Dispose();
                HOperatorSet.ImagePointsToWorldPlane(hv_CameraParam, hv_Pose, hv_Rowwy, hv_Columnwy,
                    "mm", out hv_Yxxwyx, out hv_Yxywyy);
                hv_YXRow.Dispose();
                using (HDevDisposeHelper dh = new HDevDisposeHelper())
                {
                    hv_YXRow = hv_Yxxwyx - hv_Yxnyx;
                }
                if ((int)(new HTuple(hv_YXRow.TupleLess(0))) != 0)
                {
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        {
                            HTuple
                              ExpTmpLocalVar_YXRow = -hv_YXRow;
                            hv_YXRow.Dispose();
                            hv_YXRow = ExpTmpLocalVar_YXRow;
                        }
                    }
                }
                hv_YXColumn.Dispose();
                using (HDevDisposeHelper dh = new HDevDisposeHelper())
                {
                    hv_YXColumn = hv_Yxywyy - hv_Yxnyy;
                }
                if ((int)(new HTuple(hv_YXColumn.TupleLess(0))) != 0)
                {
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        {
                            HTuple
                              ExpTmpLocalVar_YXColumn = -hv_YXColumn;
                            hv_YXColumn.Dispose();
                            hv_YXColumn = ExpTmpLocalVar_YXColumn;
                        }
                    }
                }
                //select_shape (ConnectedRegions1, SelectedRegions2, 'area', 'and', 150, 99999)
            }
            ho_Region1.Dispose();
            ho_RegionOpening.Dispose();
            ho_ConnectedRegions1.Dispose();
            ho_SelectedRegions3.Dispose();
            ho_SelectedRegions4.Dispose();
            ho_SelectedRegions5.Dispose();
            ho_Rectangle1.Dispose();

            hv_Number1.Dispose();
            hv_Number2.Dispose();
            hv_Row11.Dispose();
            hv_Column11.Dispose();
            hv_Row21.Dispose();
            hv_Column21.Dispose();
            hv_Areany.Dispose();
            hv_Rowny.Dispose();
            hv_Columnny.Dispose();
            hv_Nyx.Dispose();
            hv_Nyy.Dispose();
            hv_Nyx1.Dispose();
            hv_Nyy1.Dispose();
            hv_Yxnyx.Dispose();
            hv_Yxnyy.Dispose();
            hv_Yxxwyx.Dispose();
            hv_Yxywyy.Dispose();

            return;
        }

        public static void MeasurePinRegion(HObject ho_Image, HObject ho_ROI_0, HTuple hv_CameraParam,
            HTuple hv_Pose, HTuple hv_WindowHandle, out HTuple hv_NYX, out HTuple hv_NYY,
            out HTuple hv_YXRow, out HTuple hv_YXColumn, out HTuple hv_NYX1, out HTuple hv_NYY1,
            out HTuple hv_YXRow1, out HTuple hv_YXColumn1, out HTuple hv_Rowwy, out HTuple hv_Columnwy,
            out HTuple hv_Rowwy1, out HTuple hv_Columnwy1)
        {




            // Local iconic variables 

            HObject ho_ImageReduced, ho_Region, ho_ConnectedRegions;
            HObject ho_SelectedRegions, ho_SelectedRegions2, ho_SelectedRegions1;
            HObject ho_ObjectSelected = null, ho_ObjectSelected1 = null;
            HObject ho_Rectangle = null, ho_ObjectSelected2 = null, ho_ObjectSelected21 = null;
            HObject ho_ImageReduced1 = null, ho_ImageReduced2 = null;

            // Local control variables 

            HTuple hv_Number = new HTuple(), hv_Areawy = new HTuple();
            HTuple hv_Areawy1 = new HTuple(), hv_Row1 = new HTuple();
            HTuple hv_Column1 = new HTuple(), hv_Row2 = new HTuple();
            HTuple hv_Column2 = new HTuple();
            // Initialize local and output iconic variables 
            HOperatorSet.GenEmptyObj(out ho_ImageReduced);
            HOperatorSet.GenEmptyObj(out ho_Region);
            HOperatorSet.GenEmptyObj(out ho_ConnectedRegions);
            HOperatorSet.GenEmptyObj(out ho_SelectedRegions);
            HOperatorSet.GenEmptyObj(out ho_SelectedRegions2);
            HOperatorSet.GenEmptyObj(out ho_SelectedRegions1);
            HOperatorSet.GenEmptyObj(out ho_ObjectSelected);
            HOperatorSet.GenEmptyObj(out ho_ObjectSelected1);
            HOperatorSet.GenEmptyObj(out ho_Rectangle);
            HOperatorSet.GenEmptyObj(out ho_ObjectSelected2);
            HOperatorSet.GenEmptyObj(out ho_ObjectSelected21);
            HOperatorSet.GenEmptyObj(out ho_ImageReduced1);
            HOperatorSet.GenEmptyObj(out ho_ImageReduced2);
            hv_NYX = new HTuple();
            hv_NYY = new HTuple();
            hv_YXRow = new HTuple();
            hv_YXColumn = new HTuple();
            hv_NYX1 = new HTuple();
            hv_NYY1 = new HTuple();
            hv_YXRow1 = new HTuple();
            hv_YXColumn1 = new HTuple();
            hv_Rowwy = new HTuple();
            hv_Columnwy = new HTuple();
            hv_Rowwy1 = new HTuple();
            hv_Columnwy1 = new HTuple();
            ho_ImageReduced.Dispose();
            HOperatorSet.ReduceDomain(ho_Image, ho_ROI_0, out ho_ImageReduced);
            ho_Region.Dispose();
            HOperatorSet.Threshold(ho_ImageReduced, out ho_Region, 200, 255);
            ho_ConnectedRegions.Dispose();
            HOperatorSet.Connection(ho_Region, out ho_ConnectedRegions);
            ho_SelectedRegions.Dispose();
            HOperatorSet.SelectShape(ho_ConnectedRegions, out ho_SelectedRegions, "width",
                "and", 50, 100);
            ho_SelectedRegions2.Dispose();
            HOperatorSet.SelectShape(ho_SelectedRegions, out ho_SelectedRegions2, "height",
                "and", 50, 100);
            ho_SelectedRegions1.Dispose();
            HOperatorSet.SelectShape(ho_SelectedRegions2, out ho_SelectedRegions1, "area",
                "and", 1800, 99999);
            hv_Number.Dispose();
            HOperatorSet.CountObj(ho_SelectedRegions1, out hv_Number);
            if ((int)(new HTuple(hv_Number.TupleGreaterEqual(2))) != 0)
            {
                ho_ObjectSelected.Dispose();
                HOperatorSet.SelectObj(ho_SelectedRegions1, out ho_ObjectSelected, 1);
                ho_ObjectSelected1.Dispose();
                HOperatorSet.SelectObj(ho_SelectedRegions1, out ho_ObjectSelected1, 2);
                //获取外圆中心坐标
                hv_Areawy.Dispose(); hv_Rowwy.Dispose(); hv_Columnwy.Dispose();
                HOperatorSet.AreaCenter(ho_ObjectSelected, out hv_Areawy, out hv_Rowwy, out hv_Columnwy);
                hv_Areawy1.Dispose(); hv_Rowwy1.Dispose(); hv_Columnwy1.Dispose();
                HOperatorSet.AreaCenter(ho_ObjectSelected1, out hv_Areawy1, out hv_Rowwy1,
                    out hv_Columnwy1);
                //外圆区域抠出图像
                hv_Row1.Dispose(); hv_Column1.Dispose(); hv_Row2.Dispose(); hv_Column2.Dispose();
                HOperatorSet.SmallestRectangle1(ho_SelectedRegions1, out hv_Row1, out hv_Column1,
                    out hv_Row2, out hv_Column2);
                ho_Rectangle.Dispose();
                HOperatorSet.GenRectangle1(out ho_Rectangle, hv_Row1, hv_Column1, hv_Row2,
                    hv_Column2);
                hv_Number.Dispose();
                HOperatorSet.CountObj(ho_Rectangle, out hv_Number);
                ho_ObjectSelected2.Dispose();
                HOperatorSet.SelectObj(ho_Rectangle, out ho_ObjectSelected2, 1);
                ho_ObjectSelected21.Dispose();
                HOperatorSet.SelectObj(ho_Rectangle, out ho_ObjectSelected21, 2);
                ho_ImageReduced1.Dispose();
                HOperatorSet.ReduceDomain(ho_ImageReduced, ho_ObjectSelected2, out ho_ImageReduced1
                    );
                ho_ImageReduced2.Dispose();
                HOperatorSet.ReduceDomain(ho_ImageReduced, ho_ObjectSelected21, out ho_ImageReduced2
                    );
                //判断第一个小圆
                hv_NYX.Dispose(); hv_NYY.Dispose(); hv_YXRow.Dispose(); hv_YXColumn.Dispose();
                GetPinHW(ho_ImageReduced1, hv_CameraParam, hv_Pose, hv_Rowwy, hv_Columnwy,
                    out hv_NYX, out hv_NYY, out hv_YXRow, out hv_YXColumn);
                hv_NYX1.Dispose(); hv_NYY1.Dispose(); hv_YXRow1.Dispose(); hv_YXColumn1.Dispose();
                GetPinHW(ho_ImageReduced2, hv_CameraParam, hv_Pose, hv_Rowwy1, hv_Columnwy1,
                    out hv_NYX1, out hv_NYY1, out hv_YXRow1, out hv_YXColumn1);
            }
            HOperatorSet.DispText(hv_WindowHandle, "未找到匹配对象", "window", hv_Rowwy1,
                hv_Columnwy1, "black", new HTuple(), new HTuple());
            ho_ImageReduced.Dispose();
            ho_Region.Dispose();
            ho_ConnectedRegions.Dispose();
            ho_SelectedRegions.Dispose();
            ho_SelectedRegions2.Dispose();
            ho_SelectedRegions1.Dispose();
            ho_ObjectSelected.Dispose();
            ho_ObjectSelected1.Dispose();
            ho_Rectangle.Dispose();
            ho_ObjectSelected2.Dispose();
            ho_ObjectSelected21.Dispose();
            ho_ImageReduced1.Dispose();
            ho_ImageReduced2.Dispose();

            hv_Number.Dispose();
            hv_Areawy.Dispose();
            hv_Areawy1.Dispose();
            hv_Row1.Dispose();
            hv_Column1.Dispose();
            hv_Row2.Dispose();
            hv_Column2.Dispose();

            return;
        }

        // Local procedures 
        public static void GetLine(HObject ho_ImageGray, HTuple hv_Hight, HTuple hv_width, HTuple hv_StartRow, HTuple hv_StartColumn, HTuple hv_EndRow, HTuple hv_EndColumn, out HTuple hv_Row11, out HTuple hv_Column11, out HTuple hv_Row21, out HTuple hv_Column21)
        {




            // Local iconic variables 

            HObject ho_Regions1, ho_Line;

            // Local control variables 

            HTuple hv_ResultRow = new HTuple(), hv_ResultColumn = new HTuple();
            // Initialize local and output iconic variables 
            HOperatorSet.GenEmptyObj(out ho_Regions1);
            HOperatorSet.GenEmptyObj(out ho_Line);
            hv_Row11 = new HTuple();
            hv_Column11 = new HTuple();
            hv_Row21 = new HTuple();
            hv_Column21 = new HTuple();
            ho_Regions1.Dispose(); hv_ResultRow.Dispose(); hv_ResultColumn.Dispose();
            rake(ho_ImageGray, out ho_Regions1, 30, hv_Hight, hv_width, 1, 20, "all", "max",
                hv_StartRow, hv_StartColumn, hv_EndRow, hv_EndColumn, out hv_ResultRow, out hv_ResultColumn);
            ho_Line.Dispose(); hv_Row11.Dispose(); hv_Column11.Dispose(); hv_Row21.Dispose(); hv_Column21.Dispose();
            pts_to_best_line(out ho_Line, hv_ResultRow, hv_ResultColumn, 2, out hv_Row11,
                out hv_Column11, out hv_Row21, out hv_Column21);
            ho_Regions1.Dispose();
            ho_Line.Dispose();

            hv_ResultRow.Dispose();
            hv_ResultColumn.Dispose();

            return;
        }


        public static void Create_Stanrad_Point(HObject ho_Image, out HObject ho_RegionLines, out HObject ho_Circle, HTuple hv_ModelID1, HTuple hv_ModelID2, out HTuple hv_Standard_Row, out HTuple hv_Standard_Column, out HTuple hv_Standard_Angle)
        {
            // Local iconic variables 

            // Local control variables 

            HTuple hv_Row1 = new HTuple(), hv_Column1 = new HTuple();
            HTuple hv_Angle1 = new HTuple(), hv_Scale1 = new HTuple();
            HTuple hv_Score1 = new HTuple(), hv_Row2 = new HTuple();
            HTuple hv_Column2 = new HTuple(), hv_Angle2 = new HTuple();
            HTuple hv_Scale2 = new HTuple(), hv_Score2 = new HTuple();
            HTuple hv_Length1 = new HTuple(), hv_Length2 = new HTuple();
            // Initialize local and output iconic variables 
            HOperatorSet.GenEmptyObj(out ho_RegionLines);
            HOperatorSet.GenEmptyObj(out ho_Circle);
            hv_Standard_Row = new HTuple();
            hv_Standard_Column = new HTuple();
            hv_Standard_Angle = new HTuple();
            hv_Row1.Dispose(); hv_Column1.Dispose(); hv_Angle1.Dispose(); hv_Scale1.Dispose(); hv_Score1.Dispose();
            HOperatorSet.FindScaledShapeModel(ho_Image, hv_ModelID1, (new HTuple(-30)).TupleRad(), (new HTuple(30)).TupleRad(), 0.9, 1.1, 0.3, 1, 0.5, "least_squares", 0, 0.9, out hv_Row1, out hv_Column1, out hv_Angle1,out hv_Scale1, out hv_Score1);
            hv_Row2.Dispose(); hv_Column2.Dispose(); hv_Angle2.Dispose(); hv_Scale2.Dispose(); hv_Score2.Dispose();
            HOperatorSet.FindScaledShapeModel(ho_Image, hv_ModelID2, (new HTuple(-30)).TupleRad(), (new HTuple(30)).TupleRad(), 0.9, 1.1, 0.3, 1, 0.5, "least_squares", 0, 0.9, out hv_Row2, out hv_Column2, out hv_Angle2, out hv_Scale2, out hv_Score2);
            hv_Length1.Dispose();
            HOperatorSet.TupleLength(hv_Score1, out hv_Length1);
            hv_Length2.Dispose();
            HOperatorSet.TupleLength(hv_Score2, out hv_Length2);
            if ((int)((new HTuple(hv_Length1.TupleGreater(0))).TupleAnd(new HTuple(hv_Length2.TupleGreater(
                0)))) != 0)
            {
                ho_RegionLines.Dispose();
                HOperatorSet.GenRegionLine(out ho_RegionLines, hv_Row2, hv_Column2, hv_Row1,
                    hv_Column1);
                hv_Standard_Row.Dispose();
                using (HDevDisposeHelper dh = new HDevDisposeHelper())
                {
                    hv_Standard_Row = (hv_Row2 + hv_Row1) / 2;
                }
                hv_Standard_Column.Dispose();
                using (HDevDisposeHelper dh = new HDevDisposeHelper())
                {
                    hv_Standard_Column = (hv_Column2 + hv_Column1) / 2;
                }
                hv_Standard_Angle.Dispose();
                HOperatorSet.OrientationRegion(ho_RegionLines, out hv_Standard_Angle);
                ho_Circle.Dispose();
                HOperatorSet.GenCircle(out ho_Circle, hv_Standard_Row, hv_Standard_Column,
                    50);
            }
            else
            {
                hv_Standard_Row.Dispose();
                hv_Standard_Row = 0;
                hv_Standard_Column.Dispose();
                hv_Standard_Column = 0;
                hv_Standard_Angle.Dispose();
                hv_Standard_Angle = 0;
            }

            hv_Row1.Dispose();
            hv_Column1.Dispose();
            hv_Angle1.Dispose();
            hv_Scale1.Dispose();
            hv_Score1.Dispose();
            hv_Row2.Dispose();
            hv_Column2.Dispose();
            hv_Angle2.Dispose();
            hv_Scale2.Dispose();
            hv_Score2.Dispose();
            hv_Length1.Dispose();
            hv_Length2.Dispose();

            return;
        }

        public static void Create_Stanrad_Point(HObject ho_Image1, HObject ho_Image2, out HObject ho_RegionLines,
      out HObject ho_Circle, HTuple hv_ModelID1, HTuple hv_ModelID2, out HTuple hv_Standard_Row,
      out HTuple hv_Standard_Column, out HTuple hv_Standard_Angle)
        {




            // Local iconic variables 

            // Local control variables 

            HTuple hv_Row1 = new HTuple(), hv_Column1 = new HTuple();
            HTuple hv_Angle1 = new HTuple(), hv_Scale1 = new HTuple();
            HTuple hv_Score1 = new HTuple(), hv_Row2 = new HTuple();
            HTuple hv_Column2 = new HTuple(), hv_Angle2 = new HTuple();
            HTuple hv_Scale2 = new HTuple(), hv_Score2 = new HTuple();
            HTuple hv_Length1 = new HTuple(), hv_Length2 = new HTuple();
            // Initialize local and output iconic variables 
            HOperatorSet.GenEmptyObj(out ho_RegionLines);
            HOperatorSet.GenEmptyObj(out ho_Circle);
            hv_Standard_Row = new HTuple();
            hv_Standard_Column = new HTuple();
            hv_Standard_Angle = new HTuple();

            using (HDevDisposeHelper dh = new HDevDisposeHelper())
            {
                hv_Row1.Dispose(); hv_Column1.Dispose(); hv_Angle1.Dispose(); hv_Scale1.Dispose(); hv_Score1.Dispose();
                HOperatorSet.FindScaledShapeModel(ho_Image1, hv_ModelID1, (new HTuple(-30)).TupleRad()
                    , (new HTuple(30)).TupleRad(), 0.9, 1.1, 0.3, 1, 0.5, "least_squares", 0,
                    0.9, out hv_Row1, out hv_Column1, out hv_Angle1, out hv_Scale1, out hv_Score1);
            }
            using (HDevDisposeHelper dh = new HDevDisposeHelper())
            {
                hv_Row2.Dispose(); hv_Column2.Dispose(); hv_Angle2.Dispose(); hv_Scale2.Dispose(); hv_Score2.Dispose();
                HOperatorSet.FindScaledShapeModel(ho_Image2, hv_ModelID2, (new HTuple(-30)).TupleRad()
                    , (new HTuple(30)).TupleRad(), 0.9, 1.1, 0.3, 1, 0.5, "least_squares", 0,
                    0.9, out hv_Row2, out hv_Column2, out hv_Angle2, out hv_Scale2, out hv_Score2);
            }
            hv_Length1.Dispose();
            HOperatorSet.TupleLength(hv_Score1, out hv_Length1);
            hv_Length2.Dispose();
            HOperatorSet.TupleLength(hv_Score2, out hv_Length2);
            if ((int)((new HTuple(hv_Length1.TupleGreater(0))).TupleAnd(new HTuple(hv_Length2.TupleGreater(
                0)))) != 0)
            {
                ho_RegionLines.Dispose();
                HOperatorSet.GenRegionLine(out ho_RegionLines, hv_Row2, hv_Column2, hv_Row1,
                    hv_Column1);
                hv_Standard_Row.Dispose();
                using (HDevDisposeHelper dh = new HDevDisposeHelper())
                {
                    hv_Standard_Row = (hv_Row2 + hv_Row1) / 2;
                }
                hv_Standard_Column.Dispose();
                using (HDevDisposeHelper dh = new HDevDisposeHelper())
                {
                    hv_Standard_Column = (hv_Column2 + hv_Column1) / 2;
                }
                hv_Standard_Angle.Dispose();
                HOperatorSet.OrientationRegion(ho_RegionLines, out hv_Standard_Angle);
                ho_Circle.Dispose();
                HOperatorSet.GenCircle(out ho_Circle, hv_Standard_Row, hv_Standard_Column,
                    50);
            }
            else
            {
                hv_Standard_Row.Dispose();
                hv_Standard_Row = 0;
                hv_Standard_Column.Dispose();
                hv_Standard_Column = 0;
                hv_Standard_Angle.Dispose();
                hv_Standard_Angle = 0;
            }

            hv_Row1.Dispose();
            hv_Column1.Dispose();
            hv_Angle1.Dispose();
            hv_Scale1.Dispose();
            hv_Score1.Dispose();
            hv_Row2.Dispose();
            hv_Column2.Dispose();
            hv_Angle2.Dispose();
            hv_Scale2.Dispose();
            hv_Score2.Dispose();
            hv_Length1.Dispose();
            hv_Length2.Dispose();

            return;
        }

        public static void ReadBar_Code(HObject ho_Image, HObject ho_ROI_0, out HObject ho_SymbolRegions, out HTuple hv_DecodedDataStrings)
        {



            // Local iconic variables 

            HObject ho_GammaImage, ho_ImageReduced, ho_ImagePart;
            HObject ho_ImageScaled, ho_ImageRotate, ho_ImageMean;

            // Local control variables 

            HTuple hv_BarCodeHandle = new HTuple();
            // Initialize local and output iconic variables 
            HOperatorSet.GenEmptyObj(out ho_SymbolRegions);
            HOperatorSet.GenEmptyObj(out ho_GammaImage);
            HOperatorSet.GenEmptyObj(out ho_ImageReduced);
            HOperatorSet.GenEmptyObj(out ho_ImagePart);
            HOperatorSet.GenEmptyObj(out ho_ImageScaled);
            HOperatorSet.GenEmptyObj(out ho_ImageRotate);
            HOperatorSet.GenEmptyObj(out ho_ImageMean);
            hv_DecodedDataStrings = new HTuple();
            //convert_image_type (Image, ImageConverted, 'byte')
            ho_GammaImage.Dispose();
            HOperatorSet.GammaImage(ho_Image, out ho_GammaImage, 0.416667, 0.055, 0.0031308,
                255, "true");
            ho_ImageReduced.Dispose();
            HOperatorSet.ReduceDomain(ho_GammaImage, ho_ROI_0, out ho_ImageReduced);
            ho_ImagePart.Dispose();
            HOperatorSet.CropDomain(ho_ImageReduced, out ho_ImagePart);
            ho_ImageScaled.Dispose();
            HOperatorSet.ScaleImage(ho_ImagePart, out ho_ImageScaled, 30, 80);
            ho_ImageRotate.Dispose();
            HOperatorSet.RotateImage(ho_ImageScaled, out ho_ImageRotate, -90, "constant");
            ho_ImageMean.Dispose();
            HOperatorSet.MeanImage(ho_ImageRotate, out ho_ImageMean, 11, 16);
            hv_BarCodeHandle.Dispose();
            HOperatorSet.CreateBarCodeModel(new HTuple(), new HTuple(), out hv_BarCodeHandle);
            HOperatorSet.SetBarCodeParam(hv_BarCodeHandle, "stop_after_result_num", 1);
            ho_SymbolRegions.Dispose(); hv_DecodedDataStrings.Dispose();
            HOperatorSet.FindBarCode(ho_ImageMean, out ho_SymbolRegions, hv_BarCodeHandle,
                "auto", out hv_DecodedDataStrings);
            HOperatorSet.ClearBarCodeModel(hv_BarCodeHandle);
            ho_GammaImage.Dispose();
            ho_ImageReduced.Dispose();
            ho_ImagePart.Dispose();
            ho_ImageScaled.Dispose();
            ho_ImageRotate.Dispose();
            ho_ImageMean.Dispose();

            hv_BarCodeHandle.Dispose();

            return;
        }



        public static void pts_to_best_line(out HObject ho_Line, HTuple hv_Rows, HTuple hv_Cols, HTuple hv_ActiveNum, out HTuple hv_Row1, out HTuple hv_Column1, out HTuple hv_Row2, out HTuple hv_Column2)
        {



            // Local iconic variables 

            HObject ho_Contour = null;

            // Local control variables 

            HTuple hv_Length = new HTuple(), hv_Nr = new HTuple();
            HTuple hv_Nc = new HTuple(), hv_Dist = new HTuple(), hv_Length1 = new HTuple();
            // Initialize local and output iconic variables 
            HOperatorSet.GenEmptyObj(out ho_Line);
            HOperatorSet.GenEmptyObj(out ho_Contour);
            hv_Row1 = new HTuple();
            hv_Column1 = new HTuple();
            hv_Row2 = new HTuple();
            hv_Column2 = new HTuple();
            //初始化
            hv_Row1.Dispose();
            hv_Row1 = 0;
            hv_Column1.Dispose();
            hv_Column1 = 0;
            hv_Row2.Dispose();
            hv_Row2 = 0;
            hv_Column2.Dispose();
            hv_Column2 = 0;
            //产生一个空的直线对象，用于保存拟合后的直线
            ho_Line.Dispose();
            HOperatorSet.GenEmptyObj(out ho_Line);
            //计算边缘数量
            hv_Length.Dispose();
            HOperatorSet.TupleLength(hv_Cols, out hv_Length);
            //当边缘数量不小于有效点数时进行拟合
            if ((int)((new HTuple(hv_Length.TupleGreaterEqual(hv_ActiveNum))).TupleAnd(new HTuple(hv_ActiveNum.TupleGreater(
                1)))) != 0)
            {
                //halcon的拟合是基于xld的，需要把边缘连接成xld
                ho_Contour.Dispose();
                HOperatorSet.GenContourPolygonXld(out ho_Contour, hv_Rows, hv_Cols);
                //拟合直线。使用的算法是'tukey'，其他算法请参考fit_line_contour_xld的描述部分。
                hv_Row1.Dispose(); hv_Column1.Dispose(); hv_Row2.Dispose(); hv_Column2.Dispose(); hv_Nr.Dispose(); hv_Nc.Dispose(); hv_Dist.Dispose();
                HOperatorSet.FitLineContourXld(ho_Contour, "tukey", -1, 0, 5, 2, out hv_Row1,
                    out hv_Column1, out hv_Row2, out hv_Column2, out hv_Nr, out hv_Nc, out hv_Dist);
                //判断拟合结果是否有效：如果拟合成功，数组中元素的数量大于0
                hv_Length1.Dispose();
                HOperatorSet.TupleLength(hv_Dist, out hv_Length1);
                if ((int)(new HTuple(hv_Length1.TupleLess(1))) != 0)
                {
                    ho_Contour.Dispose();

                    hv_Length.Dispose();
                    hv_Nr.Dispose();
                    hv_Nc.Dispose();
                    hv_Dist.Dispose();
                    hv_Length1.Dispose();

                    return;
                }
                //根据拟合结果，产生直线xld
                using (HDevDisposeHelper dh = new HDevDisposeHelper())
                {
                    ho_Line.Dispose();
                    HOperatorSet.GenContourPolygonXld(out ho_Line, hv_Row1.TupleConcat(hv_Row2),
                        hv_Column1.TupleConcat(hv_Column2));
                }
            }

            ho_Contour.Dispose();

            hv_Length.Dispose();
            hv_Nr.Dispose();
            hv_Nc.Dispose();
            hv_Dist.Dispose();
            hv_Length1.Dispose();

            return;
        }

        public static void rake(HObject ho_Image, out HObject ho_Regions, HTuple hv_Elements, HTuple hv_DetectHeight, HTuple hv_DetectWidth, HTuple hv_Sigma, HTuple hv_Threshold, HTuple hv_Transition, HTuple hv_Select, HTuple hv_Row1, HTuple hv_Column1, HTuple hv_Row2, HTuple hv_Column2, out HTuple hv_ResultRow, out HTuple hv_ResultColumn)
        {




            // Stack for temporary objects 
            HObject[] OTemp = new HObject[20];

            // Local iconic variables 

            HObject ho_RegionLines, ho_Rectangle = null;
            HObject ho_Arrow1 = null;

            // Local control variables 

            HTuple hv_Width = new HTuple(), hv_Height = new HTuple();
            HTuple hv_ATan = new HTuple(), hv_i = new HTuple(), hv_RowC = new HTuple();
            HTuple hv_ColC = new HTuple(), hv_Distance = new HTuple();
            HTuple hv_RowL2 = new HTuple(), hv_RowL1 = new HTuple();
            HTuple hv_ColL2 = new HTuple(), hv_ColL1 = new HTuple();
            HTuple hv_MsrHandle_Measure = new HTuple(), hv_RowEdge = new HTuple();
            HTuple hv_ColEdge = new HTuple(), hv_Amplitude = new HTuple();
            HTuple hv_tRow = new HTuple(), hv_tCol = new HTuple();
            HTuple hv_t = new HTuple(), hv_Number = new HTuple(), hv_j = new HTuple();
            HTuple hv_DetectWidth_COPY_INP_TMP = new HTuple(hv_DetectWidth);
            HTuple hv_Select_COPY_INP_TMP = new HTuple(hv_Select);
            HTuple hv_Transition_COPY_INP_TMP = new HTuple(hv_Transition);

            // Initialize local and output iconic variables 
            HOperatorSet.GenEmptyObj(out ho_Regions);
            HOperatorSet.GenEmptyObj(out ho_RegionLines);
            HOperatorSet.GenEmptyObj(out ho_Rectangle);
            HOperatorSet.GenEmptyObj(out ho_Arrow1);
            hv_ResultRow = new HTuple();
            hv_ResultColumn = new HTuple();
            //获取图像尺寸
            hv_Width.Dispose(); hv_Height.Dispose();
            HOperatorSet.GetImageSize(ho_Image, out hv_Width, out hv_Height);
            //产生一个空显示对象，用于显示
            ho_Regions.Dispose();
            HOperatorSet.GenEmptyObj(out ho_Regions);
            //初始化边缘坐标数组
            hv_ResultRow.Dispose();
            hv_ResultRow = new HTuple();
            hv_ResultColumn.Dispose();
            hv_ResultColumn = new HTuple();
            //产生直线xld
            using (HDevDisposeHelper dh = new HDevDisposeHelper())
            {
                ho_RegionLines.Dispose();
                HOperatorSet.GenContourPolygonXld(out ho_RegionLines, hv_Row1.TupleConcat(hv_Row2),
                    hv_Column1.TupleConcat(hv_Column2));
            }
            //存储到显示对象
            {
                HObject ExpTmpOutVar_0;
                HOperatorSet.ConcatObj(ho_Regions, ho_RegionLines, out ExpTmpOutVar_0);
                ho_Regions.Dispose();
                ho_Regions = ExpTmpOutVar_0;
            }
            //计算直线与x轴的夹角，逆时针方向为正向。
            hv_ATan.Dispose();
            HOperatorSet.AngleLx(hv_Row1, hv_Column1, hv_Row2, hv_Column2, out hv_ATan);

            //边缘检测方向垂直于检测直线：直线方向正向旋转90°为边缘检测方向
            using (HDevDisposeHelper dh = new HDevDisposeHelper())
            {
                {
                    HTuple
                      ExpTmpLocalVar_ATan = hv_ATan + ((new HTuple(90)).TupleRad()
                        );
                    hv_ATan.Dispose();
                    hv_ATan = ExpTmpLocalVar_ATan;
                }
            }

            //根据检测直线按顺序产生测量区域矩形，并存储到显示对象
            HTuple end_val18 = hv_Elements;
            HTuple step_val18 = 1;
            for (hv_i = 1; hv_i.Continue(end_val18, step_val18); hv_i = hv_i.TupleAdd(step_val18))
            {
                //RowC := Row1+(((Row2-Row1)*i)/(Elements+1))
                //ColC := Column1+(Column2-Column1)*i/(Elements+1)
                //if (RowC>Height-1 or RowC<0 or ColC>Width-1 or ColC<0)
                //continue
                //endif
                //如果只有一个测量矩形，作为卡尺工具，宽度为检测直线的长度
                if ((int)(new HTuple(hv_Elements.TupleEqual(1))) != 0)
                {
                    hv_RowC.Dispose();
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        hv_RowC = (hv_Row1 + hv_Row2) * 0.5;
                    }
                    hv_ColC.Dispose();
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        hv_ColC = (hv_Column1 + hv_Column2) * 0.5;
                    }
                    //判断是否超出图像,超出不检测边缘
                    if ((int)((new HTuple((new HTuple((new HTuple(hv_RowC.TupleGreater(hv_Height - 1))).TupleOr(
                        new HTuple(hv_RowC.TupleLess(0))))).TupleOr(new HTuple(hv_ColC.TupleGreater(
                        hv_Width - 1))))).TupleOr(new HTuple(hv_ColC.TupleLess(0)))) != 0)
                    {
                        continue;
                    }
                    hv_Distance.Dispose();
                    HOperatorSet.DistancePp(hv_Row1, hv_Column1, hv_Row2, hv_Column2, out hv_Distance);
                    hv_DetectWidth_COPY_INP_TMP.Dispose();
                    hv_DetectWidth_COPY_INP_TMP = new HTuple(hv_Distance);
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        ho_Rectangle.Dispose();
                        HOperatorSet.GenRectangle2ContourXld(out ho_Rectangle, hv_RowC, hv_ColC,
                            hv_ATan, hv_DetectHeight / 2, hv_Distance / 2);
                    }
                }
                else
                {
                    //如果有多个测量矩形，产生该测量矩形xld
                    hv_RowC.Dispose();
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        hv_RowC = hv_Row1 + (((hv_Row2 - hv_Row1) * (hv_i - 1)) / (hv_Elements - 1));
                    }
                    hv_ColC.Dispose();
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        hv_ColC = hv_Column1 + (((hv_Column2 - hv_Column1) * (hv_i - 1)) / (hv_Elements - 1));
                    }
                    //判断是否超出图像,超出不检测边缘
                    if ((int)((new HTuple((new HTuple((new HTuple(hv_RowC.TupleGreater(hv_Height - 1))).TupleOr(
                        new HTuple(hv_RowC.TupleLess(0))))).TupleOr(new HTuple(hv_ColC.TupleGreater(
                        hv_Width - 1))))).TupleOr(new HTuple(hv_ColC.TupleLess(0)))) != 0)
                    {
                        continue;
                    }
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        ho_Rectangle.Dispose();
                        HOperatorSet.GenRectangle2ContourXld(out ho_Rectangle, hv_RowC, hv_ColC,
                            hv_ATan, hv_DetectHeight / 2, hv_DetectWidth_COPY_INP_TMP / 2);
                    }
                }

                //把测量矩形xld存储到显示对象
                {
                    HObject ExpTmpOutVar_0;
                    HOperatorSet.ConcatObj(ho_Regions, ho_Rectangle, out ExpTmpOutVar_0);
                    ho_Regions.Dispose();
                    ho_Regions = ExpTmpOutVar_0;
                }
                if ((int)(new HTuple(hv_i.TupleEqual(1))) != 0)
                {
                    //在第一个测量矩形绘制一个箭头xld，用于只是边缘检测方向
                    hv_RowL2.Dispose();
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        hv_RowL2 = hv_RowC + ((hv_DetectHeight / 2) * (((-hv_ATan)).TupleSin()
                            ));
                    }
                    hv_RowL1.Dispose();
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        hv_RowL1 = hv_RowC - ((hv_DetectHeight / 2) * (((-hv_ATan)).TupleSin()
                            ));
                    }
                    hv_ColL2.Dispose();
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        hv_ColL2 = hv_ColC + ((hv_DetectHeight / 2) * (((-hv_ATan)).TupleCos()
                            ));
                    }
                    hv_ColL1.Dispose();
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        hv_ColL1 = hv_ColC - ((hv_DetectHeight / 2) * (((-hv_ATan)).TupleCos()
                            ));
                    }
                    ho_Arrow1.Dispose();
                    gen_arrow_contour_xld(out ho_Arrow1, hv_RowL1, hv_ColL1, hv_RowL2, hv_ColL2,
                        25, 25);
                    //把xld存储到显示对象
                    {
                        HObject ExpTmpOutVar_0;
                        HOperatorSet.ConcatObj(ho_Regions, ho_Arrow1, out ExpTmpOutVar_0);
                        ho_Regions.Dispose();
                        ho_Regions = ExpTmpOutVar_0;
                    }
                }
                //产生测量对象句柄
                using (HDevDisposeHelper dh = new HDevDisposeHelper())
                {
                    hv_MsrHandle_Measure.Dispose();
                    HOperatorSet.GenMeasureRectangle2(hv_RowC, hv_ColC, hv_ATan, hv_DetectHeight / 2,
                        hv_DetectWidth_COPY_INP_TMP / 2, hv_Width, hv_Height, "nearest_neighbor",
                        out hv_MsrHandle_Measure);
                }

                //设置极性
                if ((int)(new HTuple(hv_Transition_COPY_INP_TMP.TupleEqual("negative"))) != 0)
                {
                    hv_Transition_COPY_INP_TMP.Dispose();
                    hv_Transition_COPY_INP_TMP = "negative";
                }
                else
                {
                    if ((int)(new HTuple(hv_Transition_COPY_INP_TMP.TupleEqual("positive"))) != 0)
                    {

                        hv_Transition_COPY_INP_TMP.Dispose();
                        hv_Transition_COPY_INP_TMP = "positive";
                    }
                    else
                    {
                        hv_Transition_COPY_INP_TMP.Dispose();
                        hv_Transition_COPY_INP_TMP = "all";
                    }
                }
                //设置边缘位置。最强点是从所有边缘中选择幅度绝对值最大点，需要设置为'all'
                if ((int)(new HTuple(hv_Select_COPY_INP_TMP.TupleEqual("first"))) != 0)
                {
                    hv_Select_COPY_INP_TMP.Dispose();
                    hv_Select_COPY_INP_TMP = "first";
                }
                else
                {
                    if ((int)(new HTuple(hv_Select_COPY_INP_TMP.TupleEqual("last"))) != 0)
                    {

                        hv_Select_COPY_INP_TMP.Dispose();
                        hv_Select_COPY_INP_TMP = "last";
                    }
                    else
                    {
                        hv_Select_COPY_INP_TMP.Dispose();
                        hv_Select_COPY_INP_TMP = "all";
                    }
                }
                //检测边缘
                hv_RowEdge.Dispose(); hv_ColEdge.Dispose(); hv_Amplitude.Dispose(); hv_Distance.Dispose();
                HOperatorSet.MeasurePos(ho_Image, hv_MsrHandle_Measure, hv_Sigma, hv_Threshold,
                    hv_Transition_COPY_INP_TMP, hv_Select_COPY_INP_TMP, out hv_RowEdge, out hv_ColEdge,
                    out hv_Amplitude, out hv_Distance);
                //清除测量对象句柄
                HOperatorSet.CloseMeasure(hv_MsrHandle_Measure);

                //临时变量初始化
                //tRow，tCol保存找到指定边缘的坐标
                hv_tRow.Dispose();
                hv_tRow = 0;
                hv_tCol.Dispose();
                hv_tCol = 0;
                //t保存边缘的幅度绝对值
                hv_t.Dispose();
                hv_t = 0;
                //找到的边缘必须至少为1个
                hv_Number.Dispose();
                HOperatorSet.TupleLength(hv_RowEdge, out hv_Number);
                if ((int)(new HTuple(hv_Number.TupleLess(1))) != 0)
                {
                    continue;
                }
                //有多个边缘时，选择幅度绝对值最大的边缘
                HTuple end_val100 = hv_Number - 1;
                HTuple step_val100 = 1;
                for (hv_j = 0; hv_j.Continue(end_val100, step_val100); hv_j = hv_j.TupleAdd(step_val100))
                {
                    if ((int)(new HTuple(((((hv_Amplitude.TupleSelect(hv_j))).TupleAbs())).TupleGreater(
                        hv_t))) != 0)
                    {

                        hv_tRow.Dispose();
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_tRow = hv_RowEdge.TupleSelect(
                                hv_j);
                        }
                        hv_tCol.Dispose();
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_tCol = hv_ColEdge.TupleSelect(
                                hv_j);
                        }
                        hv_t.Dispose();
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_t = ((hv_Amplitude.TupleSelect(
                                hv_j))).TupleAbs();
                        }
                    }
                }
                //把找到的边缘保存在输出数组
                if ((int)(new HTuple(hv_t.TupleGreater(0))) != 0)
                {
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        {
                            HTuple
                              ExpTmpLocalVar_ResultRow = hv_ResultRow.TupleConcat(
                                hv_tRow);
                            hv_ResultRow.Dispose();
                            hv_ResultRow = ExpTmpLocalVar_ResultRow;
                        }
                    }
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        {
                            HTuple
                              ExpTmpLocalVar_ResultColumn = hv_ResultColumn.TupleConcat(
                                hv_tCol);
                            hv_ResultColumn.Dispose();
                            hv_ResultColumn = ExpTmpLocalVar_ResultColumn;
                        }
                    }
                }
            }

            ho_RegionLines.Dispose();
            ho_Rectangle.Dispose();
            ho_Arrow1.Dispose();

            hv_DetectWidth_COPY_INP_TMP.Dispose();
            hv_Select_COPY_INP_TMP.Dispose();
            hv_Transition_COPY_INP_TMP.Dispose();
            hv_Width.Dispose();
            hv_Height.Dispose();
            hv_ATan.Dispose();
            hv_i.Dispose();
            hv_RowC.Dispose();
            hv_ColC.Dispose();
            hv_Distance.Dispose();
            hv_RowL2.Dispose();
            hv_RowL1.Dispose();
            hv_ColL2.Dispose();
            hv_ColL1.Dispose();
            hv_MsrHandle_Measure.Dispose();
            hv_RowEdge.Dispose();
            hv_ColEdge.Dispose();
            hv_Amplitude.Dispose();
            hv_tRow.Dispose();
            hv_tCol.Dispose();
            hv_t.Dispose();
            hv_Number.Dispose();
            hv_j.Dispose();

            return;
        }

        public static void gen_arrow_contour_xld(out HObject ho_Arrow, HTuple hv_Row1, HTuple hv_Column1, HTuple hv_Row2, HTuple hv_Column2, HTuple hv_HeadLength, HTuple hv_HeadWidth)
        {



            // Stack for temporary objects 
            HObject[] OTemp = new HObject[20];

            // Local iconic variables 

            HObject ho_TempArrow = null;

            // Local control variables 

            HTuple hv_Length = new HTuple(), hv_ZeroLengthIndices = new HTuple();
            HTuple hv_DR = new HTuple(), hv_DC = new HTuple(), hv_HalfHeadWidth = new HTuple();
            HTuple hv_RowP1 = new HTuple(), hv_ColP1 = new HTuple();
            HTuple hv_RowP2 = new HTuple(), hv_ColP2 = new HTuple();
            HTuple hv_Index = new HTuple();
            // Initialize local and output iconic variables 
            HOperatorSet.GenEmptyObj(out ho_Arrow);
            HOperatorSet.GenEmptyObj(out ho_TempArrow);
            //This procedure generates arrow shaped XLD contours,
            //pointing from (Row1, Column1) to (Row2, Column2).
            //If starting and end point are identical, a contour consisting
            //of a single point is returned.
            //
            //input parameteres:
            //Row1, Column1: Coordinates of the arrows' starting points
            //Row2, Column2: Coordinates of the arrows' end points
            //HeadLength, HeadWidth: Size of the arrow heads in pixels
            //
            //output parameter:
            //Arrow: The resulting XLD contour
            //
            //The input tuples Row1, Column1, Row2, and Column2 have to be of
            //the same length.
            //HeadLength and HeadWidth either have to be of the same length as
            //Row1, Column1, Row2, and Column2 or have to be a single element.
            //If one of the above restrictions is violated, an error will occur.
            //
            //
            //Init
            ho_Arrow.Dispose();
            HOperatorSet.GenEmptyObj(out ho_Arrow);
            //
            //Calculate the arrow length
            hv_Length.Dispose();
            HOperatorSet.DistancePp(hv_Row1, hv_Column1, hv_Row2, hv_Column2, out hv_Length);
            //
            //Mark arrows with identical start and end point
            //(set Length to -1 to avoid division-by-zero exception)
            hv_ZeroLengthIndices.Dispose();
            using (HDevDisposeHelper dh = new HDevDisposeHelper())
            {
                hv_ZeroLengthIndices = hv_Length.TupleFind(
                    0);
            }
            if ((int)(new HTuple(hv_ZeroLengthIndices.TupleNotEqual(-1))) != 0)
            {
                if (hv_Length == null)
                    hv_Length = new HTuple();
                hv_Length[hv_ZeroLengthIndices] = -1;
            }
            //
            //Calculate auxiliary variables.
            hv_DR.Dispose();
            using (HDevDisposeHelper dh = new HDevDisposeHelper())
            {
                hv_DR = (1.0 * (hv_Row2 - hv_Row1)) / hv_Length;
            }
            hv_DC.Dispose();
            using (HDevDisposeHelper dh = new HDevDisposeHelper())
            {
                hv_DC = (1.0 * (hv_Column2 - hv_Column1)) / hv_Length;
            }
            hv_HalfHeadWidth.Dispose();
            using (HDevDisposeHelper dh = new HDevDisposeHelper())
            {
                hv_HalfHeadWidth = hv_HeadWidth / 2.0;
            }
            //
            //Calculate end points of the arrow head.
            hv_RowP1.Dispose();
            using (HDevDisposeHelper dh = new HDevDisposeHelper())
            {
                hv_RowP1 = (hv_Row1 + ((hv_Length - hv_HeadLength) * hv_DR)) + (hv_HalfHeadWidth * hv_DC);
            }
            hv_ColP1.Dispose();
            using (HDevDisposeHelper dh = new HDevDisposeHelper())
            {
                hv_ColP1 = (hv_Column1 + ((hv_Length - hv_HeadLength) * hv_DC)) - (hv_HalfHeadWidth * hv_DR);
            }
            hv_RowP2.Dispose();
            using (HDevDisposeHelper dh = new HDevDisposeHelper())
            {
                hv_RowP2 = (hv_Row1 + ((hv_Length - hv_HeadLength) * hv_DR)) - (hv_HalfHeadWidth * hv_DC);
            }
            hv_ColP2.Dispose();
            using (HDevDisposeHelper dh = new HDevDisposeHelper())
            {
                hv_ColP2 = (hv_Column1 + ((hv_Length - hv_HeadLength) * hv_DC)) + (hv_HalfHeadWidth * hv_DR);
            }
            //
            //Finally create output XLD contour for each input point pair
            for (hv_Index = 0; (int)hv_Index <= (int)((new HTuple(hv_Length.TupleLength())) - 1); hv_Index = (int)hv_Index + 1)
            {
                if ((int)(new HTuple(((hv_Length.TupleSelect(hv_Index))).TupleEqual(-1))) != 0)
                {
                    //Create_ single points for arrows with identical start and end point
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        ho_TempArrow.Dispose();
                        HOperatorSet.GenContourPolygonXld(out ho_TempArrow, hv_Row1.TupleSelect(hv_Index),
                            hv_Column1.TupleSelect(hv_Index));
                    }
                }
                else
                {
                    //Create arrow contour
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        ho_TempArrow.Dispose();
                        HOperatorSet.GenContourPolygonXld(out ho_TempArrow, ((((((((((hv_Row1.TupleSelect(
                            hv_Index))).TupleConcat(hv_Row2.TupleSelect(hv_Index)))).TupleConcat(
                            hv_RowP1.TupleSelect(hv_Index)))).TupleConcat(hv_Row2.TupleSelect(hv_Index)))).TupleConcat(
                            hv_RowP2.TupleSelect(hv_Index)))).TupleConcat(hv_Row2.TupleSelect(hv_Index)),
                            ((((((((((hv_Column1.TupleSelect(hv_Index))).TupleConcat(hv_Column2.TupleSelect(
                            hv_Index)))).TupleConcat(hv_ColP1.TupleSelect(hv_Index)))).TupleConcat(
                            hv_Column2.TupleSelect(hv_Index)))).TupleConcat(hv_ColP2.TupleSelect(
                            hv_Index)))).TupleConcat(hv_Column2.TupleSelect(hv_Index)));
                    }
                }
                {
                    HObject ExpTmpOutVar_0;
                    HOperatorSet.ConcatObj(ho_Arrow, ho_TempArrow, out ExpTmpOutVar_0);
                    ho_Arrow.Dispose();
                    ho_Arrow = ExpTmpOutVar_0;
                }
            }
            ho_TempArrow.Dispose();

            hv_Length.Dispose();
            hv_ZeroLengthIndices.Dispose();
            hv_DR.Dispose();
            hv_DC.Dispose();
            hv_HalfHeadWidth.Dispose();
            hv_RowP1.Dispose();
            hv_ColP1.Dispose();
            hv_RowP2.Dispose();
            hv_ColP2.Dispose();
            hv_Index.Dispose();

            return;
        }
    }
}
